/*
#####################################################################
####################	   T R I B U I T 		#####################
#####################################################################

Copyright (C) 2010  Christoph Schnack, Berlin (Germany)

This file is part of Tribuit.

    Tribuit is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    Tribuit is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Tribuit.  If not, see <http://www.gnu.org/licenses/>.


########################################################################
*/
package GuiTools;

import java.awt.Component;
import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;

import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JPanel;

/**
 * Creates a Panel with a JLabel with the String-argument and puts
 * the Component underneath.
 * 
 * @author Christoph Schnack
 *
 */
public class LabelPanel extends JPanel{
	public JLabel label = new JLabel("",JLabel.LEFT);
	JComponent component;
	GridBagConstraints lpGbc;
	/**
	 * 
	 * @param string for the Label
	 * @param c Component
	 */
	public LabelPanel(String name, JComponent c){
		super();
		component = c;
		buildPanel(name);
	}
	
	public LabelPanel(String name, JComponent c, Font font){
		super();
		component = c;
		label.setFont(font);
		buildPanel(name);
	}
	
	private void buildPanel(String name){
		this.setLayout(new GridBagLayout());
		lpGbc = new GridBagConstraints();
		lpGbc.anchor = GridBagConstraints.NORTHWEST;
		lpGbc.fill = GridBagConstraints.HORIZONTAL;
		lpGbc.weightx=1;
		label.setText(name);
		this.add(label,lpGbc);
		lpGbc.weighty = 3;
		lpGbc.gridy=1;
		this.add(component, lpGbc);
	}
	
	public void setLabelText(String txt){
		label.setText(txt);
	}
	
	public void setComponent(JComponent c){
		this.remove(component);
		this.add(c, lpGbc);
		component = c;
	}
	
	public void setAllOpaque(boolean arg){
		this.setOpaque(arg);
		component.setOpaque(arg);
		label.setOpaque(arg);
	}
}